home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 090 / ust1a.arc / DOSB2T.C < prev    next >
Encoding:
C/C++ Source or Header  |  1985-09-05  |  2.9 KB  |  148 lines

  1.  
  2. /*+
  3.  * File: dosb2t.c
  4.  * Description:
  5.  *  dosb2t is a filter.
  6.  *  dosb2t processes i_files or the standard input.
  7.  *  dosb2t writes to o_file or standard output.
  8.  *
  9.  *  Converts a DOS binary file to text file.
  10.  *  Replaces <lf> with <cr><lf>.
  11.  *  
  12.  * Usages:
  13.  *  dosb2t [-o] <o_file> <i_files>
  14.  *
  15.  *
  16.  *  Author: Mohsen Banan.
  17.  *
  18.  *  This program is public domain software, no warranty intended or
  19.  *  implied.
  20.  *  General permission to copy or modify, but not for profit,  is
  21.  *  hereby  granted.
  22.  *
  23.  *
  24.  * Functions:
  25.  *
  26.  *
  27.  * Audit Trail:  $Log:    dosb2t.c,v $
  28.  * Revision 1.1  85/08/28  08:38:24  mohsen
  29.  * original posting to the net
  30.  * 
  31.  * 
  32.  *
  33. -*/
  34.  
  35. #ifdef RCS_VER
  36. static char *rcs = "$Header: dosb2t.c,v 1.1 85/08/28 08:38:24 mohsen Exp $";
  37. #endif
  38.  
  39. /* #includes */
  40. #include "mbstd.h"
  41. #include <stdio.h>
  42. #include <ctype.h>
  43. #include <fcntl.h>
  44. #ifdef unix
  45. #include "msc3.h"
  46. #endif
  47.  
  48. /* #defines */
  49.  
  50. /* external variables */
  51.  
  52. /* referenced external function declarations */
  53.  
  54. /* internal function declarations */
  55. PUBLIC VOID dosb2t();
  56. PUBLIC VOID cant_open();
  57. STATIC VOID usage();
  58.  
  59. /* global variables */
  60.  
  61. /* static variables */
  62. STATIC CHAR * prog_name;
  63.  
  64.  
  65. INT
  66. main (argc, argv)
  67. INT argc;
  68. CHAR * argv[];
  69. {
  70.     dosb2t(argc, argv);
  71. }
  72.     
  73.  
  74. /*<
  75.  * Function:dosb2t
  76.  * Description:
  77.  *
  78.  * Returns:
  79.  *  VOID
  80.  *  
  81. >*/
  82. PUBLIC VOID 
  83. dosb2t (argc,argv)
  84. INT argc;
  85. CHAR * argv[];
  86. {
  87.     FILE * i_fp;
  88.     FILE * o_fp;
  89.  
  90.     INT i;
  91.     INT c;
  92.  
  93.     i_fp = stdin;
  94.     o_fp = stdout;
  95.     prog_name = argv[0];
  96.     for (i=1; i<argc; ++i) {
  97.         if (*argv[i] == '-') {
  98.             /* To handle concatenated switches */
  99.             INT j;
  100.             j=i;
  101.             while (*(++argv[j])) {
  102.                 switch (*argv[j]) {
  103.                 case 'o':
  104.                 case 'O':
  105.                     if ( !(o_fp = fopen(argv[++i], "w")) ) {
  106.                         cant_open (prog_name, argv[i]);
  107.                         exit (1);
  108.                     }
  109.                     break;
  110.                 default:
  111.                     usage();
  112.                     exit(1);
  113.                 } /* switch (*argv[j]) */
  114.             } /* while (*(++argv[j])) */
  115.         } /* if '-' */
  116.         else {
  117.             if (!(i_fp = fopen (argv[i], "r"))) {
  118.                 cant_open (prog_name, argv[i]);
  119.                 exit (1);
  120.             } 
  121.             setmode (fileno(i_fp), O_BINARY);
  122.             setmode (fileno(o_fp), O_TEXT);
  123.             while (( c = getc (i_fp)) != EOF) {
  124.                 putc (c, o_fp);
  125.             }
  126.             fclose (i_fp);
  127.         }
  128.     } /* for i<argc */
  129.     fclose (o_fp);
  130.     exit (0);
  131. }
  132.  
  133. PUBLIC VOID
  134. cant_open (prog_name,filename)
  135. CHAR * prog_name;
  136. CHAR * filename;
  137. {
  138.     fprintf (stderr, "%s :can not open %s \n", prog_name, filename);
  139.  
  140. STATIC VOID
  141. usage ()
  142. {
  143.     fprintf (stderr, "Usage: %s [-o] <o_file> <i_files> \n", prog_name);
  144. }
  145.  
  146.  
  147.